/*
 * @lc app=leetcode.cn id=929 lang=java
 *
 * [929] 独特的电子邮件地址
 */

// @lc code=start
class Solution
{
  public int numUniqueEmails(String[] emails)
  {
    Set<String> email_set = new HashSet<String>();
    for (String email : emails) {
      String[] email_parts = email.split("@");
      email_set.add(getLocalname(email_parts[0]) + "@" + email_parts[1]);
    }
    return email_set.size();
  }

  String getLocalname(String name)
  {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < name.length(); i++) {
      char c = name.charAt(i);
      if (c == '.')
        continue;
      else if (c == '+')
        break;
      sb.append(c);
    }
    return sb.toString();
  }
}
// @lc code=end
